Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add utility to convert classifications to detections #1842

Merged
merged 2 commits into from
Jun 9, 2022
Merged

Conversation

ehofesmann
Copy link
Member

Adds fiftyone.utils.labels.classifications_to_detections() converting a Classifications field into a Detections field where each classification corresponds to one detection with a bounding box surrounding the entire image ([0,0,1,1]), just like classification_to_detections()

Example:

import fiftyone.zoo as foz
import fiftyone.utils.labels as foul

dataset = foz.load_zoo_dataset(
    "open-images-v6",
    split="validation",
    max_samples=50,
    label_types=["classifications"],
)

foul.classifications_to_detections(dataset, "positive_labels", "dets")

print(dataset.first())
<Sample: {
    'id': '62a0b31a79f8993392beb816',
    'media_type': 'image',
    'filepath': '/home/eric/fiftyone/open-images-v6/validation/data/0001eeaf4aed83f9.jpg',
    'tags': BaseList(['validation']),
    'metadata': None,
    'positive_labels': <Classifications: {
        'classifications': BaseList([
            <Classification: {
                'id': '62a0b31a79f8993392beb815',
                'tags': BaseList([]),
                'label': 'Airplane',
                'confidence': 1.0,
                'logits': None,
            }>,
        ]),
        'logits': None,
    }>,
    'negative_labels': <Classifications: {'classifications': BaseList([]), 'logits': None}>,
    'open_images_id': '0001eeaf4aed83f9',
    'dets': <Detections: {
        'detections': BaseList([
            <Detection: {
                'id': '62a0b32479f8993392beba90',
                'attributes': BaseDict({}),
                'tags': BaseList([]),
                'label': 'Airplane',
                'bounding_box': BaseList([0.0, 0.0, 1.0, 1.0]),
                'mask': None,
                'confidence': 1.0,
                'index': None,
            }>,
        ]),
    }>,
}>

@ehofesmann ehofesmann added feature Work on a feature request core Issues related to Core features labels Jun 8, 2022
@ehofesmann ehofesmann requested a review from a team June 8, 2022 14:38
@ehofesmann ehofesmann self-assigned this Jun 8, 2022
Copy link
Contributor

@brimoor brimoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ehofesmann ehofesmann merged commit 925f51a into develop Jun 9, 2022
@ehofesmann ehofesmann deleted the cls-to-dets branch June 9, 2022 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Issues related to Core features feature Work on a feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants